import com.alibaba.fastjson.JSONObject;
import com.api.gbhg.huangwm.BxActionV2.BxActionUtils;
import com.api.gbhg.huangwm.web.ReimbursementListApi;
import weaver.conn.RecordSet;
import weaver.general.GCONST;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author Huangwm
 * @Date 2022-05-06
 * @Version 1.0
 * @Description TODO
 **/
public class main {
    public static void main(String[] args) throws Exception {
        String rootPath = "D:\\WEAVER\\ecology\\";
        GCONST.setRootPath(rootPath);
        GCONST.setServerName("ecology");
        RecordSet rs = new RecordSet();

//        ReimbursementListApi api = new ReimbursementListApi();
//        Map<String, Object> requestParam = new HashMap<>();
//        requestParam.put("srlx",0);
//        requestParam.put("kmjxj",1);
//        requestParam.put("dygnkmbid",14);
//        requestParam.put("ysly","");
//        requestParam.put("fzysrfl","");
//        requestParam.put("dfczbkxm","");
//        requestParam.put("bmysjjfl","");
//        requestParam.put("zfysjjfl","");
//        requestParam.put("pageNumber",1);
//        requestParam.put("pageSize",10);
//        System.err.println(JSONObject.toJSONString(requestParam));
//        System.err.println(api.listV3(requestParam));
        //第一步 支出渠道为财政拨款时检查选择的渠道中的预算来源跟表单中的预算来源是否一致

        BxActionUtils utils = new BxActionUtils();
        String sql1 = "select * from formtable_main_905_dt1 where  mainid=21107";
        rs.execute(sql1);
        int i=1;
        while (rs.next()){
            int zcqd = rs.getInt("zcqd");
            //财政拨款
            if(zcqd==0){
                int ysly = rs.getInt("ysly");
                int xzkmdm = rs.getInt("xzkmdm");//财政拨款项目
                if(xzkmdm<=0){
                    throw new RuntimeException( "第"+i+"行报销信息为财拨支出时未获取到财政拨款项目");
                }
                Map<String,String> qudao = utils.getQudaoYsly(xzkmdm);
                int zfqd = Integer.parseInt(qudao.get("zfqd"));
                if(zfqd!=ysly){
                    throw new RuntimeException(  "第"+i+"行报销信息为财拨支出时渠道中的预算来源与所选预算来源不一致.渠道中为"+(zfqd==0?"当年预算":"上年结转")+" 审核选择为"+(ysly==0?"当年预算":"上年结转"));
                }
            }
            i++;
        }
    }

    public static String replaceStr(String str){
        String s =  str.replace("\"","&quot;").replace("\'","&apos;")//.replace("&","&amp;")
                .replace("<","&lt;").replace(">","&gt;");
        return s;
    }
}
